package com.sh_rw.label.common.parser;

import com.sh_rw.label.bean.BaseLabel;
import com.sh_rw.label.bean.LabelBean;
import com.sh_rw.label.bean.StatusBean;
import com.sh_rw.label.listener.ParserListener;
import com.sh_rw.label.utils.HexUtils;

/**
 * Created by rw-duke on 2018/4/8.
 */

public class _30Parser extends Parser {
    private int count;
    private int labelIndex;

    @Override
    public void onLabelParser(byte[] data, ParserListener listener) {
        if (check(data)) {
            count = data[23] & 0xff;
            BaseLabel label;
            StatusBean statusBean;
            for (int i = 0; i < count; i++) {
                labelIndex = 8 * i;

                label = new BaseLabel();
                label.setLabelType(30);
                label.set_id(data[24 + labelIndex], data[25 + labelIndex], data[26 + labelIndex]);
                statusBean = new StatusBean(data[27 + labelIndex]);
                label.setStatus(statusBean);
                label.setActiId1(data[28 + labelIndex], data[29 + labelIndex]);
                label.setActiRssi1(data[30 + labelIndex]);
                label.setHfRssi1(data[31 + labelIndex]);



//                labelBean = new LabelBean();
//                labelBean.setId(HexUtils.toHexString(data[24 + labelIndex], data[25 + labelIndex], data[26 + labelIndex]));
//                statusBean = new StatusBean(data[27 + labelIndex]);
//                labelBean.setStatus(statusBean);
//                labelBean.setAct_id1(HexUtils.toHexString(data[28 + labelIndex], data[29 + labelIndex]));
//                labelBean.setAct_rssi1(HexUtils.toHexString(data[30 + labelIndex]));
//                labelBean.setHf_rssi1(HexUtils.toHexString(data[31 + labelIndex]));

                listener.onLabelCallback(1, label);
            }
        } else {
//            listener.onError(new );
        }
    }

    @Override
    public boolean check(byte[] data) {
        return (data[13] & 0xff) == 30;
    }
}
